package controllers

import (
	"LearnProject/helpers"
	"net/http"
	qrcode "github.com/skip2/go-qrcode"
)

func GetCode(w http.ResponseWriter, r *http.Request) {
	content := r.URL.Query().Get("content")
	returnData  := make(map[string]int)
	returnData["code"] = 0
	if content == "" {
		helpers.JsonOut(w, returnData)
		return
	}

	var png []byte
	png, err := qrcode.Encode(content, qrcode.Highest, 360)


	if err != nil {
		helpers.JsonOut(w, err)
		return
	}

	//输出到浏览器
	w.Write(png)
}